<template>
  <div>
    <swiper
      ref="mySwiper"
      class="swiper"
      :options="swiperOption"
      @slideChange="slideChange"
    >
      <swiper-slide v-for="item in littleVideoList" :key="item.id">
        <div class="video-box">
          <video
            class="video"
            src="@/assets/img/ccc.mp4"
            width="100%"
            controls="controls"
          ></video>
        </div>
        <div class="bottom">
          <h3>{{item.name}}</h3>
          <p>{{item.description}}</p>
        </div>
        <div class="right">
          <div>
            <van-icon name="good-job" size="25" color="#fff"/>
            <p>{{item.follow}}</p>
          </div>
          <div>
            <van-icon name="comment-circle" size="25" color="#fff"/>
            <p>6</p>
          </div>
          <div>
            <van-icon name="share" size="25" color="#fff"/>
          </div>
          
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
import littleVideoApi from "@/api/littleVideo/littleVideo";
export default {
  name: "recom",
  data() {
    return {
      active: 0,

      queryForm: {
        pageNum: 1,
        pageSize: 6,
      },
      swiperOption: {
        direction: "vertical",
        slidesPerView: 1,
        mousewheel: true,
      },
      littleVideoList: [],
      totalLength: 6,
    };
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.$swiper;
    },
  },
  created() {
    this.getList();
  },
  methods: {
    slideChange() {
      this.active = this.$refs.mySwiper.$swiper.activeIndex;
      let activeIndex = this.$refs.mySwiper.$swiper.activeIndex + 1;
      if (activeIndex == this.totalLength) {
        this.queryForm.pageNum++;
        this.getList();
      }
      let videos = document.querySelectorAll(".video");
      for (let i = 0; i < videos.length; i++) {
        videos[i].pause();
      }
    },
    async getList() {
      let res = await littleVideoApi.pageList(this.queryForm);
      if (res.code === 20000) {
        if (this.littleVideoList.length == 0) {
          this.littleVideoList = res.data.records;
        } else {
          this.littleVideoList = this.littleVideoList.concat(res.data.records);
          this.totalLength += res.data.records.length;
        }
      } else {
        this.$toast(res.msg);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.swiper {
  width: 100%;
  height: calc(100vh - 95px);
  .swiper-slide {
    width: 100%;
    background: #000;
    position: relative;
  }
}
.video-box {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.bottom {
  color: #fff;
  position: absolute;
  left: 20px;
  bottom: 20px;
  font-size: 12px;
  p {
    width: 80%;
    margin-top: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
}
.right{
  width: 30px;
  position: absolute;
  right: 10px;
  bottom: 40px;
  color: #fff;
  font-size: 12px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  align-items: center;
  div{
    margin-bottom: 10px;
    text-align: center;
  }
}
</style>